gen emeconrandpos=0
replace emeconrandpos=1 if (V5==2)
replace emeconrandpos=2 if (V6==2)
replace emeconrandpos=3 if (V7==2)
replace emeconrandpos=4 if (V8==2)
replace emeconrandpos=5 if (V9==2)
replace emeconrandpos=6 if (V10==2)
replace emeconrandpos=7 if (V11==2)
replace emeconrandpos=8 if (V12==2)
gen wbeconrandpos=0
replace wbeconrandpos=1 if (V5==3)
replace wbeconrandpos=2 if (V6==3)
replace wbeconrandpos=3 if (V7==3)
replace wbeconrandpos=4 if (V8==3)
replace wbeconrandpos=5 if (V9==3)
replace wbeconrandpos=6 if (V10==3)
replace wbeconrandpos=7 if (V11==3)
replace wbeconrandpos=8 if (V12==3)
gen EMeconbeforeWBecon=.
replace EMeconbeforeWBecon=1 if (emeconrandpos < wbeconrandpos)
replace EMeconbeforeWBecon=0 if (emeconrandpos > wbeconrandpos)

gen selfeconrandpos=0
replace selfeconrandpos=1 if (V5==7)
replace selfeconrandpos=2 if (V6==7)
replace selfeconrandpos=3 if (V7==7)
replace selfeconrandpos=4 if (V8==7)
replace selfeconrandpos=5 if (V9==7)
replace selfeconrandpos=6 if (V10==7)
replace selfeconrandpos=7 if (V11==7)
replace selfeconrandpos=8 if (V12==7)
gen EMeconbeforeSelfecon=.
replace EMeconbeforeSelfecon=1 if (emeconrandpos < selfeconrandpos)
replace EMeconbeforeSelfecon=0 if (emeconrandpos > selfeconrandpos)

